#include <bits/stdc++.h>
using namespace std;
#define N 200005
typedef long long ll;
ll T, n, sum, ans;
ll a[N];
ll p[N];
void dfs(int x)
{
    if (x == n + 1)
    {
        sum = 0;
        ll l1 = 0, l2 = 0;
        for (int i = 1; i <= n; i++)
        {
            if (p[i] == 1)
            {
                if (a[l1] == a[i])
                    sum += a[i];
                l1 = i;
            }
            else
            {
                if (a[l2] == a[i])
                    sum += a[i];
                l2 = i;
            }
        }
        ans = max(ans, sum);
        return;
    }
    p[x] = 1;
    dfs(x + 1);
    p[x] = 2;
    dfs(x + 1);
    p[x] = 0;
}
void solve()
{
    memset(p, 0, sizeof(p));
    ans = 0;
    scanf("%lld", &n);
    for (int i = 1; i <= n; i++)
        scanf("%lld", a + i);
    dfs(1);
    printf("%lld\n", ans);
}
int main()
{
    freopen("color.in", "r", stdin);
    freopen("color.out","w",stdout);
    scanf("%lld", &T);
    while (T--)
        solve();
    return 0;
}
